using System.Linq;

namespace MediaLibraryManager
{
	partial class MediaLibraryDataContext
	{
		public static MediaLibraryDataContext GetMediaLibraryDataContext(bool logEnabled)
		{
			MediaLibraryDataContext db = new MediaLibraryDataContext();

			if (logEnabled)
				db.Log = new DebuggerWriter();

			return db;
		}
	}

	partial class Video
	{
		public static VideoFile GetVideoFile(MediaLibraryDataContext db, string filePath)
		{
			string fileName = System.IO.Path.GetFileName(filePath);

			return db.VideoFiles.Where(mv => (mv.FilePath == filePath || (mv.IsDeleted && mv.CurrentFileName == fileName))).SingleOrDefault();
		}
	}
}
